package 设计原则.里氏替换;

/**
 * @Author: kirito
 * @Date: 2024/3/7 13:11
 * @Description: TODO
 */

public class RectangleDemo {
    public static void main(String[] args) {
        //创建长方形对象
        Rectangle rectangle = new Rectangle();
        rectangle.setWidth(10);
        rectangle.setLength(20);
        //调用resize方法进行扩容
//        resize(rectangle);


        //-----------
        Square square = new Square();
        square.setLength(10);
        square.setWidth(10);
        resize(square);

    }

    //扩宽方法
    public static void resize(Rectangle rectangle) {
        //判断宽比长小，进行扩宽
        while (rectangle.getWidth() <= rectangle.getLength()) {
            rectangle.setWidth(rectangle.getWidth() + 1);
            printRectangle(rectangle);
        }
    }

    //打印长和宽
    public static void printRectangle(Rectangle rectangle) {
        System.out.println("长：" + rectangle.getLength());
        System.out.println("宽：" + rectangle.getWidth());
        System.out.println("************");
    }
}
